/**
 * 创建人:  @author huangpeng    
 * 创建时间:  2023年01月08日 17:06
 * 项目名称:  lemon-blog-cloud
 * 文件名称:  SysBaseUserFeignController
 * 文件描述:  @Description: 普通用户feign接口
 * 公司名称:  柠檬
 *
 * All rights Reserved, Designed By 柠檬 
 * @Copyright: 2022-2023
 *
 */
package com.lemon.system.controller.feign;

import com.lemon.common.core.domain.Result;
import com.lemon.common.core.utils.StringUtils;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.security.annotation.InnerAuth;
import com.lemon.system.api.domain.BiUser;
import com.lemon.system.api.model.LoginUser;
import com.lemon.system.service.BiUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 包名称：com.lemon.system.controller.feign
 * 类名称：SysBaseUserFeignController
 * 类描述：普通用户feign接口
 * 创建人：@author huangpeng
 * 创建时间：2023年01月08日 17:06
 */
@RestController
@RequestMapping("api/system/baseUser")
public class BiBaseUserFeignController {

    @Autowired
    private BiUserService userService;

    /**
     * 通过主键查询用户
     * @Title: queryBaseUserListByKey
     * @Description: 通过主键查询用户列表
     * @param userIds 多个逗号隔开
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/9/12 19:04
     */
    @GetMapping("queryBaseUserListByKey")
    public AjaxResult queryBaseUserListByKey(@RequestParam("userIds") String userIds) {
        return AjaxResult.success(userService.queryBaseUserListByKey(userIds));
    }

    /**
     * 根据userCode获取当前用户信息
     * @Title: info
     * @Description: 根据userCode获取当前用户信息
     * @param userCode
     * @return: R<LoginUser>
     * @throws:
     * @author: huangpeng
     * @Date: 2023/5/3 19:25
     */
    @InnerAuth
    @GetMapping("/info/{userCode}")
    public Result<LoginUser> info(@PathVariable("userCode") String userCode)
    {
        BiUser sysUser = userService.selectByUserCode(userCode);
        if (StringUtils.isNull(sysUser))
        {
            return Result.error("用户不存在");
        }
        LoginUser baseUserVo = new LoginUser();
        baseUserVo.setBaseUser(sysUser);
        return Result.success(baseUserVo);
    }

    /**
     * 根据email获取当前用户信息
     * @Title: getInfoByEmail
     * @Description: 根据email获取当前用户信息
     * @param email
     * @return: R<LoginUser>
     * @throws:
     * @author: huangpeng
     * @Date: 2023/5/3 19:25
     */
    @InnerAuth
    @GetMapping("/getInfoByEmail/{email}")
    public Result<LoginUser> getInfoByEmail(@PathVariable("email") String email)
    {
        BiUser sysUser = userService.selectByEmail(email);
        if (StringUtils.isNull(sysUser))
        {
            return Result.error("用户不存在");
        }
        LoginUser baseUserVo = new LoginUser();
        baseUserVo.setBaseUser(sysUser);
        return Result.success(baseUserVo);
    }

    /**
     * 根据phone获取当前用户信息
     * @Title: getInfoByPhone
     * @Description: 根据phone获取当前用户信息
     * @param phone
     * @return: R<LoginUser>
     * @throws:
     * @author: huangpeng
     * @Date: 2023/5/3 19:25
     */
    @InnerAuth
    @GetMapping("/getInfoByPhone/{phone}")
    public Result<LoginUser> getInfoByPhone(@PathVariable("phone") String phone)
    {
        BiUser sysUser = userService.selectByPhone(phone);
        if (StringUtils.isNull(sysUser))
        {
            return Result.error("用户不存在");
        }
        LoginUser baseUserVo = new LoginUser();
        baseUserVo.setBaseUser(sysUser);
        return Result.success(baseUserVo);
    }

    /**
     * 通过资料来源平台的当前用户唯一uid获取当前用户信息
     * @Title: getInfoByOriginUid
     * @Description: 通过资料来源平台的当前用户唯一uid获取当前用户信息
     * @param originUid 资料来源平台的当前用户唯一uid
     * @param thirdSource 第三方系统类型
     * @return: R<LoginUser>
     * @throws:
     * @author: huangpeng
     * @Date: 2023/5/3 19:25
     */
    @InnerAuth
    @GetMapping("/getInfoByOriginUid")
    public Result<LoginUser> getInfoByOriginUid(@RequestParam("originUid") String originUid, @RequestParam("thirdSource") String thirdSource) {
        BiUser biUser = userService.selectByUuidAndSource(originUid, thirdSource);
        if (biUser == null) {
            return Result.success(null);
        } else {
            LoginUser baseUserVo = new LoginUser();
            baseUserVo.setBaseUser(biUser);
            return Result.success(baseUserVo);
        }
    }
}
